/* 
 * File:   IPTManager.h
 * Author: bharat
 *
 * Created on October 21, 2009, 10:11 PM
 */

#ifndef _IPTMANAGER_H
#define	_IPTMANAGER_H

#include "P2Defs.h"

#include "IPTEntry.h"
#include "bitmap.h"

class Lock;

class IPTManager {
private:
    BitMap* physPages; // bitmap for the physical pages

    IPTEntry* ipt;

    Lock* iptLock ;
    unsigned int nextEntryAge ;

public:

    int previousPID ;
    
    IPTManager() ;

    IPTEntry* SearchIPT(int pid, int vpn);

    int addIPTEntry(IPTEntry* nEntry) ;

    unsigned int getNextAge() ;

    /*
     * Picks up any entry form IPT (according to replacement policy). Also swaps it out if needed.
     * Return the freeed PPN if success, else return -1.
     */

    int FreeAnyPage(int pid) ;

    int markAsDirty(int pid, int vpn, bool dirty, int ppn , int loc) ;

    void printIPT() ;

    int getPhysPage(int pid) ;
    
    int freePhysPage(int pid,int vpn, int ppn) ;
};

#endif	/* _IPTMANAGER_H */

